package com.example.ruiji.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ruiji.common.Result;
import com.example.ruiji.entity.Category;
import com.example.ruiji.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public Result<Page<Category>> pageResult(Integer page, Integer pageSize) {
        return categoryService.Page(page, pageSize);
    }

    @PostMapping
    public Result<String> add(@RequestBody Category category) {
        return categoryService.add(category);
    }

    @DeleteMapping
    public Result<String> delete(Long ids) {
        return categoryService.delete(ids);
    }

    @PutMapping
    public Result<String> update(@RequestBody Category category) {
        return categoryService.update(category);
    }

    @GetMapping("/list")
    public Result<List<Category>> list(Category category) {
        return categoryService.getCategories(category);
    }
}
